package com.test.action;

import java.util.Iterator;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.ActionSupport;
import com.painarthur.rbac.action.BaseAction;
import com.test.bean.Student;
import com.test.bean.Teacher;
import com.test.service.TeacherService;

@ParentPackage("default")
@Namespace(value = "/")
public class TeacherActioin extends BaseAction {
	private static final long serialVersionUID = 1L;

	@Autowired
	Teacher teacher;
	@Autowired
	TeacherService teacherService;

	@Action("addTeacher")
	public String addTeacher() {
		teacher.setTeacher_id("22");
		teacher.setTeacherName("bbb");
		teacherService.addTeacher(teacher);
		return "success";
	}

	// 寰楀埌涓�釜Teacher瀹炰綋
	@Action("getOneTeacher")
	public String getOneTeacher() {
		String teacherId = "22";
		teacher = teacherService.getOneTeacher(teacherId);
		System.out.println("id=" + teacher.getTeacher_id() + ",name="
				+ teacher.getTeacherName());
		return "success";
	}

	// 杩斿洖缁撴灉鏄痩ist
	@Action("getTeacherAndStudentList")
	public String getTeacherAndStudentList() {
		List<Teacher> list = teacherService.getTeacherAndStudentList();
		Iterator<Teacher> iter = list.iterator();
		while (iter.hasNext()) {
			teacher = iter.next();
			System.out.println("name is " + teacher.getTeacherName());
		}
		return "success";
	}

	@SuppressWarnings("rawtypes")
	@Action("getTeacherAndStudent")
	public String getTeacherAndStudent() {
		teacher = teacherService.getTeacherAndStudent();
		List list = teacher.getStudents();
		Iterator iter = list.iterator();
		while (iter.hasNext()) {
			Student student = (Student) iter.next();
			System.out.println("student's name is " + student.getStudent_name());
			System.out.println("");
		}
		return "success";
	}
}